<!doctype html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport"
              content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>10-mutations中常量的使用</title>
    </head>
    <body>
        <div id="app">
            {{count}}
            <button @click="change">++</button>
            <button @click="change5">++5</button>
        </div>
        <script src='../js/vue.js'></script>
        <script src="../js/vuex.js"></script>
        <script>
            let mapState = Vuex.mapState;

            const SOME_MUTATION='SOME_MUTATION'
            let store = new Vuex.Store({
                state: {
                    count: 10
                },
                mutations: {
                    addCount(state) {
                        state.count++;
                    },
                    [SOME_MUTATION](state,payload){
                        console.log(payload.n);
                        state.count+=payload.n;
                    }
                }
            })

            let vm = new Vue({
                el: "#app",
                computed: {
                    ...mapState(['count']),
                },
                store,
                data: {},
                methods: {
                    change() {
                        this.$store.commit('addCount')
                    },
                    change5(){
                        this.$store.commit({
                            type:'SOME_MUTATION',
                            n:5
                        })
                    }
                }
            });
        </script>
    </body>
</html>